package com.zzcy.bt_print_plugin.utils;

import android.os.Handler;
import android.os.Looper;

public class ThreadUtil {

	/**
	 * 在子线程执行
	 * 
	 * @param r
	 */
	public static void runOnBackThread(Runnable r) {
//		new Thread(r).start();
		ThreadPoolManager.getInstance().createLongThreadPool().execute(r);
	}
	
	public static void runOnShortThead(Runnable r){
		ThreadPoolManager.getInstance().createShortThreadPool().execute(r);
	}

	private static Handler handler = new Handler(Looper.getMainLooper());

	public static boolean isUiThread() {
		return Looper.myLooper() == Looper.getMainLooper();
	}

	/**
	 * 在主线程执行
	 */
	public static void runOnUIThread(Runnable r) {
		if (isUiThread()) {
			r.run();
		} else {
			handler.post(r);
		}
	}

}
